// pages/Login/Judgeuser/Judgeuser.js
var businessLogic = require('../../../utils/NetWork/Model/LoginbusinessLogic.js')
var common = require('../../../utils/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid:"",
    width:"",
    height:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res.windowWidth)
        console.log(res.windowHeight)
        that.setData({
          width: res.windowWidth+'rpx',
          height: res.windowHeight + 'px',
        });
      }
    })  
    this.getOpenIdTap();
    
  },
  Judgeuser:function(res){
    common.setStorageSync("openid",res)
  
    let params = { "orgid": "999999999", userid: "5d79d9ad-f522-40c3-accf-96f569cbaef5", "searchField": "openid", "searchValue": res};
     businessLogic.weixinhao(params, (res) => {

       if (res == "" || res ==undefined){
         wx.redirectTo({
           url: '../boundwx/boundwx?tiaoid=0',
         })
       }else{
         common.setStorageSync("user", res)
         
         wx.redirectTo({
           url: '../logining/logining',
         })
       }
    
     })
  },
  getOpenIdTap: function () {
    const APP_ID = 'wxa55c46fa368839d0';//输入小程序appid  
    const APP_SECRET = '601eaed7d28a1ea95dfc775fa2c78911';//输入小程序app_secret  
    var OPEN_ID = ''//储存获取到openid  
    var SESSION_KEY = ''//储存获取到session_key 
    var that = this;
    wx.login({
      success: function (res) {
        wx.request({
          //获取openid接口  
          url: 'https://api.weixin.qq.com/sns/jscode2session',
          data: {
            appid: APP_ID,
            secret: APP_SECRET,
            js_code: res.code,
            grant_type: 'authorization_code'
          },
          method: 'GET',
          success: function (res) {
            console.log(res.data)
            OPEN_ID = res.data.openid;//获取到的openid  
            SESSION_KEY = res.data.session_key;//获取到session_key 
            console.log(OPEN_ID)
            console.log(SESSION_KEY)
            that.Judgeuser(OPEN_ID);
         
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})